import { Component, OnInit ,Input,Output,EventEmitter} from '@angular/core';

@Component({
  selector: 'inherit-base-pag',
  template: `
    <button (click)="previousPage()" [disabled]="!hasPrevious()">{{previousText}}</button> 
    <button (click)="nextPage()" [disabled]="!hasNext()">{{nextText}}</button>
    <p>page {{ page }} of {{ pageCount }} </p>
  `,
  styles: []
})
export class InheritBasePagComponent implements OnInit {

  @Input() pageCount:number;
  @Input() page:number;
  @Input() previousText:string='previous'
  @Input() nextText:string='next'
  @Output() pageChanged=new EventEmitter<number>();
  constructor() { }

  nextPage(){
      this.pageChanged.emit(++this.page);
  }
  previousPage(){
      this.pageChanged.emit(--this.page)
  }
  hasNext(){
      return this.page<this.pageCount;
  }
  hasPrevious(){
    return this.page>1
  }

  ngOnInit() {
  }

}
